<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/* Start of file print.php */
/* Location: ./cashflow/controllers/print.php */
class Printing extends CI_Controller {
	
	function __construct(){
		parent::__construct();
        $this->load->model('accounts'); /** load table rekening **/ 
        if(!$this->session->userdata('username')) /** restrict area if not acces to login page**/
			redirect('/',301); 
    }
    
    function cheque(){
        $this->ws->set('title',lang('recap_cheque'));/** title page */
		$this->ws->set('username',$this->session->userdata('username')); /** username session */
		$this->ws->set('department',$this->session->userdata('dep')); /** departement session */
        $this->ws->set('accounts',$this->accounts->getAccountData()); /** table rekening */
        $this->ws->set_theme('smooth'); /** set theme to smooth*/
		$this->ws->view('printing/index'); /** view layout to views/print/cheque*/
    }
    
    function getPrintingCheque(){
        /** post to variabel **/ 
        $date           =   $this->input->post('day').'-'.$this->input->post('month').'-'.$this->input->post('year');
        $information    =   $this->input->post('information');
        $account        =   $this->input->post('account');
        $total          =   $this->input->post('total');
        
        /** get Account Information **/
        $acc    =   $this->accounts->getAccount($account); /** account**/
        $kurs   =   $acc['MataUang'];
        $branch =   $acc['Branch'];
        
        if($kurs == "IDR"):
    	   $number   = '('.IndonesianNumericToWord($total,3) .' Rupiah )';
    	   $value    = " Rp. ".number_format($total,0,",",".") ;
        elseif($kurs == "USD"):
    	   $number   = '('.EnglishNumericToWord($total).')';
    	   $value    = " USD. ".number_format($total,2,".",",");
        endif;  
        
        $pdf = tcpdf();
        $pdf->setPrintHeader(false);
        $pdf->setPrintFooter(false);
        $k=0;
        $pdf->AddPage(); 
        /** initialization of x & y axis **/
        $x_axis_initial = 20;
        $y_axis_initial = 20;
        $x_axis = $x_axis_initial;
        $y_axis = $y_axis_initial;
        
        /** pdf setup**/ 
        $pdf->SetFont('helvetica', '', 9);
        $pdf->SetFillColor(255, 255, 255);
        $pdf->SetTextColor(0, 0, 0);
        $pdf->SetDrawColor(0, 0, 0);
        $pdf->SetLineWidth(0.3);  
        
        $y_axis0=$y_axis+7; 
        $y_axis=$y_axis;
        
        $pdf->SetY($y_axis); $pdf->SetX($x_axis_initial);
        $pdf->Cell(165, 4, $date, 0, 0, 'R', 1); 
        
        $y_axis=$y_axis+30; 
        $pdf->SetY($y_axis); $pdf->SetX(100);
        $pdf->Cell(165, 4, 'PT. BAYU BUANA GEMILANG', 0, 0, 'L', 1); 
        
        $y_axis=$y_axis+4; 
        $pdf->SetY($y_axis); $pdf->SetX(100);
        $pdf->Cell(165, 4, 'Jl. Jend. Sudirman Kav. 59', 0, 0, 'L', 1); 
        
        $y_axis=$y_axis+4; 
        $pdf->SetY($y_axis); $pdf->SetX(100);
        $pdf->Cell(165, 4, 'Plaza Abda Lt. 16 (021)51400145/146', 0, 0, 'L', 1); 
        
        $y_axis=$y_axis+7; 
        $pdf->SetY($y_axis); $pdf->SetX($x_axis_initial);
        $pdf->Cell(165, 4, 'MONO ARINTA', 0, 0, 'L', 1); 
        
        $y_axis=$y_axis+4; 
        $pdf->SetY($y_axis); $pdf->SetX($x_axis_initial);
        $pdf->Cell(165, 4, '0000-957-128', 0, 0, 'L', 1); 
        
        $y_axis=$y_axis+7;
        $pdf->SetY($y_axis); $pdf->SetX($x_axis_initial);
        $pdf->Cell(165, 4, $branch, 0, 0, 'L', 1); 
        
        $y_axis=$y_axis+7;
        
        $pdf->SetY($y_axis); $pdf->SetX($x_axis_initial+3);
        $pdf->MultiCell(55, 4, $information, 0, 'L', 0, 0, '', '', true); 
        $y_axis=$y_axis+5;
        
        $pdf->SetY($y_axis); $pdf->SetX(115);
        $pdf->Cell(65, 4, $value, 0, 0, 'L', 1); 
        
        $y_axis=$y_axis+4;
        
        $pdf->SetY($y_axis); $pdf->SetX(115);
        $pdf->Cell(65, 4, $number, 0, 0, 'L', 1);
        
        $pdf->Output("cheque.pdf","I");
        
    }
}    